#include <project_common.h>
#include "systick_timer.h"
#include "led.h"
int main(void) {
    // gpio_setup();
    // systick_setup();
    led_gpio_setup();
    systick_timer_init(1000);  // 初始化 SysTick 定时器，周期为 1000ms

    uint8_t led_state = 0;

    // 自动初始化USART1，使用默认参数
    usart_auto_init(USART1);
    usart_send_string(USART1, "USART1 auto initialized, using default settings.\r\n");

    // 手动初始化USART2，自定义参数
    UsartParameters custom_params = {
        .baudrate = 9600,
        .databits = 8,
        .stopbits = USART_STOPBITS_1,
        .parity = USART_PARITY_NONE,
        .flow_control = USART_FLOWCONTROL_NONE,
        .mode = USART_MODE_TX_RX
     };
    usart_manual_init(USART2, &custom_params);
    usart_send_string(USART2, "USART2 manually initialized, using custom settings.\r\n");

    uint8_t led_switched = 0;
    while (1) {
        uint64_t current_count = systick_timer_get_count();
        if (current_count % 1000 == 0 && current_count > 0) {
            if (!led_switched) {
                led_state =!led_state;
                led_update_state(led_state);
                led_switched = 1;
            }
        } else {
            led_switched = 0;
        }
    }

    return 0;
}    